<?php 

require_once("model/loginBD.php");
function select_answer_forum($id_forum) {
	$query = "SELECT id_answer, id_forum, id_user, text_answer, date_answer FROM answer where id_forum = $id_forum"; 
								 
	logIn();
	$result = mysql_query($query) or die('Erreur SQL !'.$query.'<br>'.mysql_error());	
	logOut();
	$total = mysql_num_rows($result);
	if($total) {
		$i = 0;
		while($row = mysql_fetch_array($result)) {
			$tab['id_answer'][$i] = $row['id_answer'];
			$tab['id_forum'][$i] = $row['id_forum'];
			$tab['id_user'][$i] = $row['id_user'];
			$tab['text_answer'][$i] = $row['text_answer'];
			$tab['date_answer'][$i] = $row['date_answer'];
			++$i;
		}
	}
	if( mysql_num_rows($result) > 0) return $tab;	else return 0;
}
function add_answer_db($id_forum, $id_user, $text_answer) {
	$query = "INSERT INTO answer (id_answer, id_forum, id_user, text_answer, date_answer) 
			  VALUES (NULL, '".$id_forum."', '".$id_user."', '".$text_answer."', SYSDATE())";
	logIn();
	mysql_query($query) or die('Erreur SQL !'.$query.'<br>'.mysql_error());
	logOut();
	return true;
}

function select_nb_answer_forum($id_forum) {
	$query = "SELECT count(*) AS nb_rep FROM answer where id_forum = $id_forum"; 
								 
	logIn();
	$result = mysql_query($query) or die('Erreur SQL !'.$query.'<br>'.mysql_error());	
	logOut();
	return mysql_fetch_array($result);
}

?>